#include "util.h"

//定义
QThreadPool *globalThreadPool = QThreadPool::globalInstance();

void setPushBtn(QPushButton *btn,
                const QString &objectName,
                const QSize &size,
                const QString &text,
                const QString &styleSheet,
                bool useIcon,
                const QString &iconURL,
                const uint8_t width,
                const uint8_t heigth)
{
    btn->setObjectName(objectName);
    btn->setMinimumSize(size);
    btn->setMaximumSize(size);
    btn->setText(text);
    btn->setStyleSheet(styleSheet);
    if (useIcon) {
        QIcon icon(iconURL);
        btn->setIcon(icon);
        if (width == 0 && heigth == 0) {
            btn->setIconSize(btn->size());
        } else {
            btn->setIconSize(QSize(width, heigth));
        }
    }
}

void setLable(QLabel *label,
              const QString &objectName,
              const QString &labelText,
              const QString &FontFamily,
              const uint8_t fontSize)
{
    label->setObjectName(objectName);
    label->setAlignment(Qt::AlignCenter);
    label->setText(labelText);
    QFont font = label->font();
    font.setFamily(FontFamily);
    font.setPointSize(fontSize);
    font.setWeight(QFont::Medium);
    font.setStyleStrategy(QFont::PreferAntialias); //设置开启抗锯齿
    label->setFont(font);
    label->setStyleSheet("color: rgb(80, 80, 80);");
}

void setQFont(QFont &font, const QString &FontFamily, const uint8_t fontSize, bool Bold)
{
    font.setFamily(FontFamily);
    font.setPointSize(fontSize);
    font.setStyleStrategy(QFont::PreferAntialias); //设置开启抗锯齿
    font.setBold(Bold);
}

void changeIcon(QAbstractButton *btn, const QString &iconURL)
{
    QIcon icon(iconURL);
    btn->setIcon(icon);
    btn->setIconSize(btn->size());
}

QLabel *addSpaceLabel(QSize size)
{
    QLabel *spaceLabel = new QLabel();
    spaceLabel->setObjectName("spaceLabel");
    // spaceLabel->setMaximumSize(size);
    spaceLabel->setMinimumSize(size);
    spaceLabel->setStyleSheet(R"(QLabel{border:none;})");
    return spaceLabel;
}
